package gorreteapps.amigoinvisible.lists;

import gorreteapps.amigoinvisible.R;

import java.util.ArrayList;

import android.app.Activity;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.widget.ArrayAdapter;
import android.widget.TextView;

public class FriendInfoAdapter extends ArrayAdapter<FriendInfo>{

	private ArrayList<FriendInfo> friendsInfo;
	private Activity context;
	
	public FriendInfoAdapter(Activity context, ArrayList<FriendInfo> friendsInfo) {
		super(context, R.layout.friend_info, friendsInfo);
		this.context = context;
		this.friendsInfo = friendsInfo;
	}

	public View getView(int position, View view, ViewGroup parent){
		
		View item = view;
		ViewHolder holder;
		
		if(item == null){
			LayoutInflater inflater = context.getLayoutInflater();
			item = inflater.inflate(R.layout.friend_info, null);
			
			holder = new ViewHolder();
			holder.name = (TextView) item.findViewById(R.id.friendName);
			holder.email = (TextView) item.findViewById(R.id.friendEmail);
			
			item.setTag(holder);
		}
		else{
			holder = (ViewHolder) item.getTag();
		}
		
		holder.name.setText(friendsInfo.get(position).getName());
		holder.email.setText(friendsInfo.get(position).getEmail());
		
		return item;
	}
	
	/**
	 * Need to optimize the listview
	 *
	 */
	private static class ViewHolder{
		TextView name;
		TextView email;
	}
}
